<?php
/**
 * @author: liaofei<136327134@qq.com>
 * @day: 2021/6/4
 */

namespace App\Dao\store;

use App\Dao\BaseDao;
use App\Models\store\UnStoreModel;



/**平台管理
 * Class StoreDao
 * @package app\dao\store
 */
class StoreDao extends BaseDao
{
   
    public function setModel(){
        return UnStoreModel::class;
    }
    
   
    /**
     * 平台列表
     * @param string 
     */
    public function StoreList($where,$select)
    {
        //名称搜索 +时间搜索
        $name=$where['name'];
        $between=$where['between'];
        //获取管理员id
        
        $admin_id=$where['user_info']['id'];
        
        $return_list = $this->models::where([])->when(!empty($where['create_time']), function ($query) use ($between) {
           
            return $query->whereBetween('created_at', $between);
        })->when(!empty($where['name']), function ($query) use ($name) {
            
            return $query ->whereRaw("concat(IFNULL(account,''),IFNULL(phone,''),IFNULL(un_name,'')) like ?",["%$name%"]);
          
        })->when(!empty($where['user_info']['level']), function ($query) use ($admin_id) {
            return $query ->where('creator_uid', $admin_id);
           
        })
        ->select($select)->orderBy('created_at','desc') ->paginate($where['limit']);
        
        $return_list ->each(function($item){
            
           
            $item->link_url = env('APP_CONTRACT_API_URL', 'http://192.168.1.199:84').'/admin/#/admin/login/login/?store_id='.$item['store_randomnum'];
            return $item;
        });
        
        $res = $this->formatData($return_list);
       
        return  $res;
       
    }

    
    /**
     * 判断账号是否存在
     */
    public  function  IsStore(array $where,string $id){
        return $this->models::where($where)->where('id','!=',$id)->count();
    }
    
  
   
}